﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AirlineProject.Models
{
    public class TicketModels
    {
        private DataClassesProjectAirlineDataContext dc = new DataClassesProjectAirlineDataContext();
        public List<Ticket> status(int id)
        {
            return this.dc.Tickets.Where(s => s.flight_id == id).ToList();
        }
        public bool AddTicket(string ticket_id, string bill_id, int flight_id, DateTime ticket_date, int type_id, int child_num, string class1, double ticket_price, int status, int payment_id)
        {
            bool result = true;
            try
            {
                Ticket t = new Ticket();
                t.ticket_id = ticket_id;
                t.bill_id = bill_id;
                t.flight_id = flight_id;
                t.ticket_date = ticket_date;
                t.type_id = type_id;
                t.child_num = child_num;
                t.class1 = class1;
                t.ticket_price = ticket_price;
                t.status = status;
                t.Payment_id = payment_id;
                this.dc.Tickets.InsertOnSubmit(t);
                this.dc.SubmitChanges();
            }
            catch
            {
                result = false;
            }
            return result;
        }
        public List<Ticket> ListStatus(int id)
        {
            return this.dc.Tickets.Where(s => s.status == id).ToList();
        }
        public Ticket InfoTicket(string id)
        {
            return this.dc.Tickets.Single(t=>t.ticket_id==id);
        }
        public List<Ticket> ListType(int id)
        {
            return this.dc.Tickets.Where(lt=>lt.type_id==id).ToList();
        }
        public bool processprice(double ticket_price)
        {
            bool kq = true;
            try
            {
                Ticket t = new Ticket();
                t.ticket_price = ticket_price;
                this.dc.Tickets.InsertOnSubmit(t);
                this.dc.SubmitChanges();
            }
            catch
            {
                kq = false;
            }
            return kq;
        }
    }
}